<html>
<head><meta charset="utf-8"><title>Decoding a `SymbolName` · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html">Decoding a `SymbolName`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203467795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203467795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203467795">(Jul 10 2020 at 04:12)</a>:</h4>
<p>I'm attempting <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_middle/ty/mod.rs#L2991-L2996">this FIXME</a>, converting a <code>Symbol</code> to a <code>&amp;'tcx str</code>. But I can't work out how to write the <code>Decodable</code> impl.</p>



<a name="203467838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203467838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203467838">(Jul 10 2020 at 04:12)</a>:</h4>
<p>I tried this:</p>



<a name="203467840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203467840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203467840">(Jul 10 2020 at 04:12)</a>:</h4>
<div class="codehilite"><pre><span></span><code>    fn decode&lt;D: Decoder&gt;(d: &amp;mut D) -&gt; Result&lt;SymbolName&lt;&#39;tcx&gt;, D::Error&gt; {
        ty::tls::with(|tcx| { Ok(Self::new(tcx, &amp;d.read_str()?)) })
    }
</code></pre></div>



<a name="203467843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203467843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203467843">(Jul 10 2020 at 04:12)</a>:</h4>
<p>But I get "<code>tcx</code> is a reference that is only valid in the closure body"</p>



<a name="203467999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203467999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203467999">(Jul 10 2020 at 04:16)</a>:</h4>
<p>Maybe this isn't possible, and the FIXME comment is just a bad suggestion? <code>Decodable</code> doesn't seem compatible with a type that refers to <code>tcx</code>-owned data.</p>



<a name="203468163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203468163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203468163">(Jul 10 2020 at 04:20)</a>:</h4>
<p>Unless <code>UseSpecializedDecodable</code> can somehow come to the rescue? I haven't worked out what it does, yet</p>



<a name="203468528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203468528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203468528">(Jul 10 2020 at 04:30)</a>:</h4>
<p>/me finds the <code>arena_types</code> macro...</p>



<a name="203471614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203471614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203471614">(Jul 10 2020 at 05:51)</a>:</h4>
<p>/me gets something working</p>



<a name="203485324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Decoding%20a%20%60SymbolName%60/near/203485324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60.html#203485324">(Jul 10 2020 at 09:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120989">njn</span> <a href="#narrow/stream/131828-t-compiler/topic/Decoding.20a.20.60SymbolName.60/near/203468163">said</a>:</p>
<blockquote>
<p>Unless <code>UseSpecializedDecodable</code> can somehow come to the rescue? I haven't worked out what it does, yet</p>
</blockquote>
<p>it lets you specialize on the decoder type. but <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> has a better approach to replace that mess</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>